package com.jelly.util;

import java.util.Arrays;
import java.util.Collection;

/**
 * 灵巧打印机
 * @author Jelly
 *
 */
public class PPrint {
	
	/**
	 * 从Collection中产生格式化的String
	 * @param Collection
	 * @return String
	 */
	public static String pformat(Collection<?> c){
		if(c.size()==0)return "[]";
		StringBuffer result = new StringBuffer("[");
		for (Object elem : c) {
			if(c.size()!=1){
				result.append("\n ");
			}
			result.append(elem);
		}
		if(c.size()!=1){
			result.append("\n");
		}
		result.append("]");
		return result.toString();
	}
	public static void pprint(Collection<?> c){
		System.out.println(pformat(c));
	}
	
	public static void pprint(Object[] c){
		System.out.println(pformat(Arrays.asList(c)));
	}
	
	public static void main(String[] args) {
		String [] temp={"s","ss"};
		pprint(temp);
		String[] temp2 ={"12"};
		pprint(temp2);
	}
	
}
